package com.zy.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zy.business.domain.TbPunchCard;
import com.zy.common.core.domain.entity.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;


/**
 * @Description:打卡提醒Mapper接口
 * @author: zhangxiaojia
 * @date: 2020/7/16 上午 10:45
 */
public interface PunchCardMapper extends BaseMapper<TbPunchCard> {

    List<TbPunchCard> list();

    @Select("select * from tb_punch_card where ding_user_id=#{dingUserId} order by create_time desc limit 1")
    TbPunchCard getLastPunchCard(@Param("dingUserId") String dingUserId);

    TbPunchCard getLastPunchCardByDingUserId(@Param("dingUserId") String dingUserId);

    List<TbPunchCard> getByStatus(@Param("status") Integer status, @Param("state") Integer state, @Param("isRemind") Integer isRemind);

    @Select("select ding_user_id from tb_punch_card where (status=0 or (status=2 and punch_card_time is null)) and state=#{state}")
    List<String> getNotClockedInUserId(@Param("state") Integer state);

    @Select("select * from tb_punch_card where state=#{state} and (status=0 or (status=2 and punch_card_time is null))")
    List<TbPunchCard> getMissCard(@Param("state") Integer state);


    List<Map<String, Object>> getListByDateRemind(@Param("userId") Long userId, @Param("date") String date);


    List<Map<String, Object>> getListByDate(@Param("userId") Long userId, @Param("date") String date);


    @Select("select * from tb_punch_card where DATE(CREATE_TIME) = #{date} and user_id=#{userId}")
    List<TbPunchCard> getUserListByDate(@Param("userId") Long userId, @Param("date") String date);

    @Select("select * from tb_punch_card where DATE(CREATE_TIME) = #{date} and user_id=#{userId} and state=#{state}")
    TbPunchCard getPunchCardByStateAndDate(@Param("userId") Long userId, @Param("date") String date, @Param("state") Integer state);


    Long monthCount(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("userId") Long userId, @Param("status") Integer status);

    int updateByDate(@Param("userId") Long userId, @Param("date") String date, @Param("state") Integer[] state);

    List<TbPunchCard> getUserPunchCard(@Param("userId") Long userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
    List<Map<String, Object>> getYesterdayData(Long deptId);

    Map<String, Object> getMyAttendance(@Param("userId") Long userId, @Param("startTime") String startTime, @Param("endTime") String endTime);

    List<Map<String, Object>> selectMyAttendance(@Param("userId") Long userId, @Param("date") String date);

    List<Map<String, Object>> selectTodayAttendance(SysUser user);
}
